package myJs.user.workflow.featureSelection.svm

import cats.effect.SyncIO
import myJs.Implicits._
import myJs.Utils._
import myJs.cps._
import myJs.tool.Tool
import myJs.tool.Tool._
import myJs.user.mission.plot._
import myJs.user.workflow.featureSelection.AllFSSoft.FSSoftT
import org.scalajs.dom.document
import scalatags.Text.all._
import shared.Pojo._

import scala.collection.immutable.SeqMap
import myJs.myPkg.reactHookForm._
import shared.pojo.WorkflowMission._
import com.softwaremill.quicklens._
import myJs.user.FeatureSelectionTool

/** Created by yz on 2/12/2020
  */
object Svm extends FSSoftT with SvmSoftT {

  override def refreshResult(idStr: String): Unit = {
    super.refreshResult(idStr)
    Tool.initMiniColors
    SvmPlotTab.init(idStr)
    FeatureSelectionTool.resultShow(idStr)
  }

  override def appendData(
      fieldArray: UseFieldArrayRT,
      fsData: FsData,
      fsDataChange: FsData => SyncIO[Unit],
      nodeId: String,
      extraData: ExtraData
  ) = {
    SyncIO{} >> {
      val eachData = EachSvmData(nodeId = nodeId, groups = extraData.groups)
      val newFsData = fsData.modify(_.svm).using(_ :+ eachData)
      fieldArray.append(eachData)
      fsDataChange(newFsData)
    }
  }

  override def fieldArray(useForm: UseFormRT): UseFieldArrayRT = ReactHookForm.useFieldArray(
    UseFieldArrayOptions(
      control = useForm.control,
      name = "svm"
    )
  )

  override def cp(
      fieldArray: UseFieldArrayRT,
      fsData: FsData,
      fsDataChange: FsData => SyncIO[Unit],
      fsDataModifyF: (FsData => FsData) => SyncIO[Unit],
      showIdStr: String,
      extraData: ExtraData,
      extraDataChange: ExtraData => SyncIO[Unit]
  ) = {
    Cp.Props(
      fieldArray = fieldArray,
      fsData = fsData,
      fsDataChange = fsDataChange,
      fsDataModifyF = fsDataModifyF,
      showIdStr = showIdStr,
      extraData = extraData
    ).render
  }

  override def removeData(fsData: FsData, fsDataChange: FsData => SyncIO[Unit], curI: Int) = {
    SyncIO{} >> {
      val newData = fsData.modify(_.svm).using(_.removed(curI))
      fsDataChange(newData)
    }
  }

}
